<html>
<head><meta charset="utf-8"><title>Foreign exceptions should be UB under -C panic=abort · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html">Foreign exceptions should be UB under -C panic=abort</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="184715163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715163">(Jan 03 2020 at 07:15)</a>:</h4>
<p>In <span class="user-mention" data-user-id="116009">@nikomatsakis</span>'s draft he says:</p>
<blockquote>
<p>Changing the behavior from <code>-Cpanic=unwind</code> to <code>-Cpanic=abort</code> should not cause Undefined Behavior.</p>
</blockquote>



<a name="184715165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715165">(Jan 03 2020 at 07:16)</a>:</h4>
<p>I don't think that it is possible to guarantee this in practice.</p>



<a name="184715224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715224">(Jan 03 2020 at 07:17)</a>:</h4>
<p>The main issue is the granularity at which we can catch exceptions. We basically have 2 options:</p>
<ul>
<li>Catch only Rust panics. This is used by <code>catch_unwind</code>.</li>
<li>Catch all types of exceptions. This is used by drop cleanups.</li>
</ul>



<a name="184715277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715277">(Jan 03 2020 at 07:18)</a>:</h4>
<p>The only way to make foreign exceptions non-UB under -C panic=abort would be to catch all types of foreign exceptions around calls to potentially unwinding FFI functions and then abort.</p>



<a name="184715289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715289">(Jan 03 2020 at 07:19)</a>:</h4>
<p>However this means that we would abort on functions like <code>pthread_exit</code> and even <code>longjmp</code> (on Windows).</p>



<a name="184715355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715355">(Jan 03 2020 at 07:21)</a>:</h4>
<p>The current consensus is that unwinding across Rust code is allowed if there is nothing to drop in the unwound frames (i.e. unwinding is equivalent to <code>longjmp</code>). However if we made foreign exceptions abort under -C panic=abort then these cases would no longer work.</p>



<a name="184715401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715401">(Jan 03 2020 at 07:22)</a>:</h4>
<p>Or to rephrase the question: is unwinding allowed under -C panic=abort if there are no destructors in the unwound frames?</p>



<a name="184715419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715419">(Jan 03 2020 at 07:23)</a>:</h4>
<p>My position would be to just say that unwinding into code compiled with -C panic=abort is UB if the unwind would have run any destructors. This matches the semantics of C++ code compiled with <code>-fno-exceptions</code>.</p>



<a name="184715671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715671">(Jan 03 2020 at 07:30)</a>:</h4>
<p>One option that would work is to keep emitting drop code but just replacing the contents with a call to <code>abort</code>. This allows foreign unwinding to work fine through frames with no destructors, but aborts if any destructors are found. However you then lose the code size benefits.</p>



<a name="184715887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184715887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184715887">(Jan 03 2020 at 07:36)</a>:</h4>
<p>In summary, the 3 options for -C panic=abort are:</p>
<ol>
<li>Foreign exceptions are UB if they would have caused a destructor to run.</li>
<li>Wrap FFI calls and abort if an exception leaks out of them. This breaks <code>longjmp</code> and <code>pthread_exit</code>.</li>
<li>Keep emitting destructors but have them simply call <code>abort</code>. This will increase code size.</li>
</ol>



<a name="184723881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184723881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184723881">(Jan 03 2020 at 10:33)</a>:</h4>
<p>For option 3, we might be able to make up the code size in the common case of "few unknown calls" by only emitting aborting destructors once for known call stacks (e.g., if you know everything will hit main without getting caught, then you can have the abort on unwind in main, right?)</p>



<a name="184723948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184723948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184723948">(Jan 03 2020 at 10:34)</a>:</h4>
<p>you'd need to be a bit more careful -- it's not just call stack, I guess, but more so "destructor containing stack"</p>



<a name="184734133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184734133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184734133">(Jan 03 2020 at 13:43)</a>:</h4>
<blockquote>
<p>One option that would work is to keep emitting drop code but just replacing the contents with a call to <code>abort</code>. This allows foreign unwinding to work fine through frames with no destructors, but aborts if any destructors are found. However you then lose the code size benefits.</p>
</blockquote>
<p>Well, you keep some, right?</p>



<a name="184734178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184734178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184734178">(Jan 03 2020 at 13:43)</a>:</h4>
<p>I think it's not only longjmp but even segfaults that trigger unwinding in Windows (<span class="user-mention" data-user-id="116015">@Alex Crichton</span> said something like that to me at one point) -- you are correct that we need to consider that.</p>



<a name="184734299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184734299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184734299">(Jan 03 2020 at 13:45)</a>:</h4>
<p>Is it possible to identify those cases (e.g., by checking the type of the exception) and allow them to continue unwinding, while intercepting other things?</p>



<a name="184734432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184734432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184734432">(Jan 03 2020 at 13:47)</a>:</h4>
<p>I sort of remember assuming something like this at some point but forgetting about it.</p>



<a name="184735987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184735987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184735987">(Jan 03 2020 at 14:08)</a>:</h4>
<p>We don't really have control over that since we are using _CxxFrameHandler3 as our personality function.</p>



<a name="184736386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184736386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184736386">(Jan 03 2020 at 14:14)</a>:</h4>
<p>Control over what exceptions we intercept?</p>



<a name="184736619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184736619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184736619">(Jan 03 2020 at 14:18)</a>:</h4>
<p>Presumably we could also test in the shim, though obviously that would make it more complex?</p>



<a name="184736736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184736736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184736736">(Jan 03 2020 at 14:20)</a>:</h4>
<p>I'm pondering how much this wrinkle changes things. </p>
<p>In particular, one of the advantages of the "C unwind" variant is that it identifies the "possible unwinding" cases more narrowly (though just <em>how</em> narrow such cases are is less than clear to me, given this annoying wrinkle of pthreads triggering unwinding from functions like <code>read</code>). </p>
<p>If we decide that foreign exceptions executing dtors if just UB, then this doesn't matter one way or the other.</p>
<p>If we do insert shims, it might matter, but only if we can put the shim at the <em>call site</em>. If, as you point out, we have to potentially catch the unwinding at any point, that's not helpful at all.</p>



<a name="184736982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184736982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184736982">(Jan 03 2020 at 14:24)</a>:</h4>
<p>I had a look through LLVM and it seems that it sets a flag on the generated function to make it ignore all SEH exceptions except longjmp.</p>



<a name="184737064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737064">(Jan 03 2020 at 14:25)</a>:</h4>
<p>So longjmp and C++ exceptions will run destructors, but SEH exceptions from segfaults won't.</p>



<a name="184737198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737198">(Jan 03 2020 at 14:27)</a>:</h4>
<p>LLVM does this? Or our LLVM backend does this?</p>



<a name="184737214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737214">(Jan 03 2020 at 14:28)</a>:</h4>
<p>Do C++ exceptions not count as SEH exceptions?</p>



<a name="184737273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737273">(Jan 03 2020 at 14:28)</a>:</h4>
<p>(I'm trying to understand what you wrote; it seems like "ignores all SEH exceptions" would also mean C++ exceptions are ignored)</p>



<a name="184737427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737427">(Jan 03 2020 at 14:30)</a>:</h4>
<p>Another option, incidentally, would be to say that "unwinding that may execute dtors is UB" (as you said) but -- in debug mode -- to make those dtors abort</p>



<a name="184737444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737444">(Jan 03 2020 at 14:30)</a>:</h4>
<p>whereas in release mode they are simply compiled out</p>



<a name="184737497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737497">(Jan 03 2020 at 14:31)</a>:</h4>
<blockquote>
<p>So longjmp and C++ exceptions will run destructors, but SEH exceptions from segfaults won't.</p>
</blockquote>
<p>This isn't true in our code, right? Or at least, with <code>-Cpanic=abort</code>, we strip out all the landing pads and mark everything as "no unwind", so presumably our destructors don't run</p>



<a name="184737709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737709">(Jan 03 2020 at 14:34)</a>:</h4>
<p>Sorry, I mean that when generating EH tables, the LLVM backend sets a flag to indicate that only C++ exception and longjmp are handled. This flag is read by _CxxFrameHandler3 and it indicates that all SEH exceptions except C++ exceptions and longjmp are ignored.</p>



<a name="184737748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737748">(Jan 03 2020 at 14:35)</a>:</h4>
<p>I see.</p>



<a name="184737789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737789">(Jan 03 2020 at 14:36)</a>:</h4>
<p>Thanks</p>



<a name="184737900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184737900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184737900">(Jan 03 2020 at 14:37)</a>:</h4>
<p>I'm presuming here that we want longjmp to continue working correctly (i.e. it is well-defined to unwind through frames with no destructors) on both panic=unwind and panic=abort.</p>



<a name="184738024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738024">(Jan 03 2020 at 14:38)</a>:</h4>
<p>Also, we want the same to apply to pthread_exit (on Linux): it should be able to safely unwind through Rust code as long as that code has no destructors.</p>



<a name="184738230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738230">(Jan 03 2020 at 14:41)</a>:</h4>
<p>Yes, I think that is correct.</p>



<a name="184738237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738237">(Jan 03 2020 at 14:41)</a>:</h4>
<p>I guess <span class="user-mention" data-user-id="143274">@Amanieu</span> another option would be that the "abort shim" inspects the inspection that is thrown</p>



<a name="184738242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738242">(Jan 03 2020 at 14:41)</a>:</h4>
<p>and checks if it originates from longjmp</p>



<a name="184738244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738244">(Jan 03 2020 at 14:41)</a>:</h4>
<p>If so, it is "re-raised"</p>



<a name="184738248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738248">(Jan 03 2020 at 14:41)</a>:</h4>
<p>and otherwise, we abort</p>



<a name="184738251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738251">(Jan 03 2020 at 14:41)</a>:</h4>
<p>it makes the shim more complex of course</p>



<a name="184738256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738256">(Jan 03 2020 at 14:41)</a>:</h4>
<p>but it seems "locallized" to the call site at least, rather than being infectious?</p>



<a name="184738302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738302">(Jan 03 2020 at 14:42)</a>:</h4>
<blockquote>
<p>Yes, I think that is correct.</p>
</blockquote>
<p>to be clear, I think it's correct that we want <code>longjmp</code> to work</p>



<a name="184738310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738310">(Jan 03 2020 at 14:42)</a>:</h4>
<p><code>pthread_exit</code> is a really interesting wrinkle that I don't know how to think about</p>



<a name="184738326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738326">(Jan 03 2020 at 14:42)</a>:</h4>
<p>I don't think it's all that useful to guarantee that it works "only if there are no dtors"</p>



<a name="184738340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738340">(Jan 03 2020 at 14:42)</a>:</h4>
<p>well, I mean, I guess it's potentially useful</p>



<a name="184738368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738368">(Jan 03 2020 at 14:43)</a>:</h4>
<p>Actually what I meant is "it works <em>under -C panic=abort</em> only if there are no dtors".</p>



<a name="184738372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738372">(Jan 03 2020 at 14:43)</a>:</h4>
<p>right</p>



<a name="184738393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738393">(Jan 03 2020 at 14:43)</a>:</h4>
<p>Under -C panic=unwind it would always work, and run destructors while unwinding.</p>



<a name="184738395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738395">(Jan 03 2020 at 14:43)</a>:</h4>
<p>on windows</p>



<a name="184738400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738400">(Jan 03 2020 at 14:43)</a>:</h4>
<p>pthread_exit is on Linux</p>



<a name="184738440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738440">(Jan 03 2020 at 14:44)</a>:</h4>
<p>I presume longjmp over a frame with dtors would be UB, as it is in C++</p>



<a name="184738455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738455">(Jan 03 2020 at 14:44)</a>:</h4>
<p>Yes</p>



<a name="184738461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738461">(Jan 03 2020 at 14:44)</a>:</h4>
<p>(but <em>on windows</em> it would potentially be guaranteed to unwind and execute dtors)</p>



<a name="184738469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738469">(Jan 03 2020 at 14:44)</a>:</h4>
<p>Also true</p>



<a name="184738470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738470">(Jan 03 2020 at 14:44)</a>:</h4>
<p><code>pthread_exit</code> is kind of different</p>



<a name="184738488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738488">(Jan 03 2020 at 14:45)</a>:</h4>
<p>in that you might want to declare that it executes dtors with <code>-Cpanic=unwind</code> , but is UB with <code>-Cpanic=abort</code> unless there are no dtors</p>



<a name="184738491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738491">(Jan 03 2020 at 14:45)</a>:</h4>
<p>The basic rule is: if you unwind across a Rust frame, you <em>must</em> execute destructors.</p>



<a name="184738496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738496">(Jan 03 2020 at 14:45)</a>:</h4>
<p>Yes, this rule must be guaranteed for sure.</p>



<a name="184738588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738588">(Jan 03 2020 at 14:46)</a>:</h4>
<p>Incidentally, musl's pthread_exit which doesn't unwind is still UB to use if there are frames with destructors on the stack, since pthread_exit frees the stack which implicitly acts as unwinding the frames without running their destructors.</p>



<a name="184738663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738663">(Jan 03 2020 at 14:47)</a>:</h4>
<p>Presumably also true in C++</p>



<a name="184738831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738831">(Jan 03 2020 at 14:49)</a>:</h4>
<p>I don't think it is explicitly said in the C++ standard (since the C++ standard library doesn't have an equivalent of pthread_exit), but probably true.</p>



<a name="184738893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184738893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184738893">(Jan 03 2020 at 14:50)</a>:</h4>
<blockquote>
<p>The basic rule is: if you unwind across a Rust frame, you <em>must</em> execute destructors.</p>
</blockquote>
<p>mostly I imagine this same rule applies in C++</p>



<a name="184739023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184739023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184739023">(Jan 03 2020 at 14:52)</a>:</h4>
<p>C++ does explicitly say that skipping destructors with longjmp is UB.</p>



<a name="184739940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184739940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184739940">(Jan 03 2020 at 15:02)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I updated the <a href="https://hackmd.io/PMlTBQS2T1i_a3lBW0348g?view#To-avoid-UB--Cpanicabort-will-require-some-shims-if-we-permit-foreign-exceptions-that-did-not-originate-from-a-Rust-panic" target="_blank" title="https://hackmd.io/PMlTBQS2T1i_a3lBW0348g?view#To-avoid-UB--Cpanicabort-will-require-some-shims-if-we-permit-foreign-exceptions-that-did-not-originate-from-a-Rust-panic">corresponding hackmd section</a>, take a look</p>



<a name="184740676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184740676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184740676">(Jan 03 2020 at 15:12)</a>:</h4>
<p>A few typos: "land pads" "cod"</p>



<a name="184740700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184740700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184740700">(Jan 03 2020 at 15:12)</a>:</h4>
<p>Mostly correct</p>



<a name="184744223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744223">(Jan 03 2020 at 15:56)</a>:</h4>
<p>thanks</p>



<a name="184744226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744226">(Jan 03 2020 at 15:56)</a>:</h4>
<p>my bluetooth keyboard is dying a bit I think :)</p>



<a name="184744246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744246">(Jan 03 2020 at 15:56)</a>:</h4>
<p>some keys I have to press a few times or they don't register... leads to typos like "cod" :)</p>



<a name="184744269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744269">(Jan 03 2020 at 15:57)</a>:</h4>
<p>(although I'm plenty prone to typos with any keyboard...)</p>



<a name="184744393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744393">(Jan 03 2020 at 15:58)</a>:</h4>
<p>I was surprised <span class="user-mention" data-user-id="143274">@Amanieu</span> to see you talking about <code>pthread_exit</code>; I thought it was <code>pthread_cancel</code> that sometimes used unwinding</p>



<a name="184744422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744422">(Jan 03 2020 at 15:58)</a>:</h4>
<p>I don't see much discussion of this in <a href="http://man7.org/linux/man-pages/man3/pthread_exit.3.html" target="_blank" title="http://man7.org/linux/man-pages/man3/pthread_exit.3.html">the man page</a></p>



<a name="184744639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744639">(Jan 03 2020 at 16:00)</a>:</h4>
<blockquote>
<p>The current consensus is that unwinding across Rust code is allowed if there is nothing to drop in the unwound frames (i.e. unwinding is equivalent to longjmp)</p>
</blockquote>
<p>There is consensus about this.</p>



<a name="184744663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744663">(Jan 03 2020 at 16:01)</a>:</h4>
<p>However, there is also consensus that there are some destructors that it is not incorrect not to call.</p>



<a name="184744758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744758">(Jan 03 2020 at 16:02)</a>:</h4>
<p>Example:</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">Foo</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="nb">Drop</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">fn</span> <span class="nf">drop</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">longjmp</span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="184744791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744791">(Jan 03 2020 at 16:02)</a>:</h4>
<p>In fact, there are actually very few destructors that must be called for safety.</p>



<a name="184744805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744805">(Jan 03 2020 at 16:03)</a>:</h4>
<p>Some examples would be <code>Pin</code>, <code>crossbeam::scope</code>, etc.</p>



<a name="184744846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744846">(Jan 03 2020 at 16:03)</a>:</h4>
<p>For example, not calling the destructor of a <code>Vec</code> leaks the vector, but that's something  that we already say its safe.</p>



<a name="184744966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184744966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184744966">(Jan 03 2020 at 16:05)</a>:</h4>
<p>This is orthogonal to whether we define not calling those constructors as UB or not. We can artificially say that deallocating a stack variable without calling its destructor is UB, even if, depending on the actual destructor, the operation is actually safe.</p>



<a name="184745116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184745116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184745116">(Jan 03 2020 at 16:06)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <a href="https://github.com/bminor/glibc/blob/cf4dfd461725b6dbe6f27fbd16913f2c6c5cf7c5/nptl/pthread_exit.c#L24" target="_blank" title="https://github.com/bminor/glibc/blob/cf4dfd461725b6dbe6f27fbd16913f2c6c5cf7c5/nptl/pthread_exit.c#L24">pthread_exit</a> calls <a href="https://github.com/bminor/glibc/blob/cf4dfd461725b6dbe6f27fbd16913f2c6c5cf7c5/nptl/pthreadP.h#L302" target="_blank" title="https://github.com/bminor/glibc/blob/cf4dfd461725b6dbe6f27fbd16913f2c6c5cf7c5/nptl/pthreadP.h#L302">__do_cancel</a> which calls <a href="https://github.com/bminor/glibc/blob/cf4dfd461725b6dbe6f27fbd16913f2c6c5cf7c5/nptl/unwind.c#L111" target="_blank" title="https://github.com/bminor/glibc/blob/cf4dfd461725b6dbe6f27fbd16913f2c6c5cf7c5/nptl/unwind.c#L111">__pthread_unwind</a> which calls _Unwind_ForcedUnwind.</p>



<a name="184745125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184745125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184745125">(Jan 03 2020 at 16:07)</a>:</h4>
<p>I'm not sure this UB buys us any optimizations, but this would maybe buy us a more simpler specification.</p>



<a name="184745181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184745181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184745181">(Jan 03 2020 at 16:07)</a>:</h4>
<p>I say maybe because it is, for example, possible to construct a <code>Pin</code> on the heap, and deallocate it without running its destructor using <code>unsafe</code> code. So <code>Pin</code> already documents that running its destructor before the <code>Pin</code> is deallocated is required for safety.</p>



<a name="184745527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184745527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184745527">(Jan 03 2020 at 16:12)</a>:</h4>
<p>And crossbeam scope should probably do the same if its API allows that to happen.</p>



<a name="184868779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184868779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184868779">(Jan 05 2020 at 22:47)</a>:</h4>
<blockquote>
<p>We don't really have control over that since we are using _CxxFrameHandler3 as our personality function.</p>
</blockquote>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> </p>
<p>Is writing our own personality function possible/feasible? Would that simplify the problem at all?</p>



<a name="184869071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184869071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184869071">(Jan 05 2020 at 22:54)</a>:</h4>
<p>Eh, maybe, but difficult. A lot of the SEH stuff is undocumented APIs that LLVM had to reverse engineer.</p>



<a name="184869080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184869080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184869080">(Jan 05 2020 at 22:55)</a>:</h4>
<p>On the other hand, we need to decide whether a C++ exception is allowed to unwind across Rust frames that have no destructors.</p>



<a name="184869085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184869085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184869085">(Jan 05 2020 at 22:55)</a>:</h4>
<p>(under -C panic=abort)</p>



<a name="184869133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184869133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184869133">(Jan 05 2020 at 22:56)</a>:</h4>
<p>We've got some consensus that we should allow this for longjmp and pthread_exit (forced unwind) at least, since those work with C code.</p>



<a name="184869650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184869650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184869650">(Jan 05 2020 at 23:10)</a>:</h4>
<p>You've mentioned "forced unwind" before (and Alex Crichton mentioned it in the PR preventing <code>-Cpanic=abort</code> from aborting on <code>longjmp</code>). Is that standard ABI nomenclature?</p>



<a name="184869661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184869661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184869661">(Jan 05 2020 at 23:10)</a>:</h4>
<p>My impression (from that PR) was that forced unwinding is reasonably simple to detect</p>



<a name="184870456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184870456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184870456">(Jan 05 2020 at 23:35)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <span class="user-mention" data-user-id="143274">@Amanieu</span> Come to think of it, I have a more fundamental question. Is the <code>-Cpanic=abort</code> issue actually related to the question of whether or not to introduce <code>"C unwind"</code>? Isn't it something we'll need to address either way?</p>



<a name="184870506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184870506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184870506">(Jan 05 2020 at 23:36)</a>:</h4>
<p>If the way we handle <code>-Cpanic=abort</code> isn't directly related to the <code>"C unwind"</code> question, then I don't think that discussion belongs in the blog post, which should remain focused on <code>"C/unwind"</code></p>



<a name="184890246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/184890246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#184890246">(Jan 06 2020 at 09:18)</a>:</h4>
<p>It is tangentially related since one of the arguments for "C unwind" was that it with panic=abort the compiler would only have to add catch blocks to "C unwind" functions instead of all "C" functions.</p>



<a name="185006040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/185006040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#185006040">(Jan 07 2020 at 12:34)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> why are we using that particular personality function ?</p>



<a name="185006072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/185006072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#185006072">(Jan 07 2020 at 12:35)</a>:</h4>
<p>There is, e.g., <code>_CxxFrameHandler4</code></p>



<a name="185006900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/185006900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#185006900">(Jan 07 2020 at 12:48)</a>:</h4>
<p>Because that's the only one that LLVM currently supports.</p>



<a name="185009352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/185009352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#185009352">(Jan 07 2020 at 13:23)</a>:</h4>
<p>:/</p>



<a name="185063686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Foreign%20exceptions%20should%20be%20UB%20under%20-C%20panic%3Dabort/near/185063686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Foreign.20exceptions.20should.20be.20UB.20under.20-C.20panic.3Dabort.html#185063686">(Jan 07 2020 at 22:53)</a>:</h4>
<blockquote>
<p>Come to think of it, I have a more fundamental question. Is the <code>-Cpanic=abort</code> issue actually related to the question of whether or not to introduce <code>"C unwind"</code>? Isn't it something we'll need to address either way?</p>
</blockquote>
<p><span class="user-mention" data-user-id="120076">@Kyle Strand</span> Yes, I believe it is something we have to address either way, and the blog post tries to emphasize that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>